package com.jd.threed.阻塞队列原理;

import java.util.concurrent.ArrayBlockingQueue;

public class BlockingQueue1 {


    public static void main(String[] args) {

        ArrayBlockingQueue queue = new ArrayBlockingQueue<Object>(10);


        Runnable producer = () -> {
            while (true) {
                try {
                    queue.put(new Object());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        new Thread(producer).start();
        new Thread(producer).start();

        Runnable consumer = () -> {
            while (true) {
                try {
                    queue.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        new Thread(consumer).start();

        new Thread(consumer).start();

    }
}
